import React from 'react';

import ReactEcharts from 'echarts-for-react';
import { LineProps } from '../chart.interface';

export class BarChart extends React.Component<LineProps, {}> {
  static defaultProps = {
    categories: [],
    series: [],
  };

  constructor(props: LineProps) {
    super(props);
  }

  prepareOption = (): any => {
    const option = {
      color: ['rgb(64,144,233)', 'rgb(128,215,250)'],
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow',
        },
      },
      grid: {
        top: '5%',
        left: '10%',
        right: '4%',
        bottom: '3%',
      },
      xAxis: {
        show: false,
        type: 'value',
        splitLine: {
          show: false,
        },
      },
      yAxis: {
        type: 'category',
        data: this.props.categories,
      },
      series: [] as any,
    };

    for (const s of this.props.series!) {
      option.series.push({
        name: s.name,
        type: 'bar',
        stack: '总量',
        data: s.data,
        showBackground: true,
        backgroundStyle: {
          color: '#1b2431',
        },
      });
    }
    return option;
  };

  render() {
    return (
      <ReactEcharts option={...this.prepareOption()} style={{ height: '240px', width: '100%' }} />
    );
  }
}
